﻿// --------------------------------------------------------------------------------------------------------------------
// <copyright file="ThemedResourceLocator.cs" company="XamlNinja">
//   2011 Richard Griffin and Ollie Riches
// </copyright>
// <summary>
//   The themed resource locator.
// </summary>
// --------------------------------------------------------------------------------------------------------------------


namespace WP7Contrib.Services.Resources
{
    using System.IO;
    using System.Windows;
    using System.Windows.Media;

    /// <summary>
    /// The themed resource locator.
    /// </summary>
    public class ThemedResourceLocator
    {
        /// <summary>
        /// The theme.
        /// </summary>
        private readonly Wp7Theme theme;

        /// <summary>
        /// Initializes a new instance of the <see cref="ThemedResourceLocator"/> class.
        /// </summary>
        public ThemedResourceLocator()
        {
            var resource = Application.Current.Resources["PhoneForegroundColor"];
            if (resource != null)
            {
                this.theme = (Color)resource == Color.FromArgb(222, 0, 0, 0) ? Wp7Theme.Light : Wp7Theme.Dark;
            }
            else
            {
                this.theme = Wp7Theme.Dark;
            }
        }

        /// <summary>
        /// The wp 7 theme.
        /// </summary>
        public enum Wp7Theme
        {
            /// <summary>
            /// The dark.
            /// </summary>
            Dark, 

            /// <summary>
            /// The light.
            /// </summary>
            Light
        }

        /// <summary>
        /// Gets FavoriteImageSource.
        /// </summary>
        public string FavoriteImageSource 
        { 
            get 
            { 
                return this.GetImagePath("appbar.favs.rest.png"); 
            } 
        }

        /// <summary>
        /// Gets ContextBackgroundColor.
        /// </summary>
        public string ContextBackgroundColor
        {
            get
            {
                return this.theme == Wp7Theme.Dark ? "White" : "Black";
            }
        }

        /// <summary>
        /// Gets ContextForegroundColor.
        /// </summary>
        public string ContextForegroundColor
        {
            get
            {
                return this.theme == Wp7Theme.Dark ? "Black" : "White";
            }
        }

        /// <summary>
        /// The get image path.
        /// </summary>
        /// <param name="fileName">
        /// The file name.
        /// </param>
        /// <returns>
        /// The get image path.
        /// </returns>
        private string GetImagePath(string fileName)
        {
            var folder = this.theme == Wp7Theme.Dark ? "/Resources/Images/Dark/" : "/Resources/Images/Light/";
            return Path.Combine(folder, fileName);
        }
    }
}
